﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Timers;
using System.Media;

namespace PacMan
{
    
    public partial class GameForm : Form
    {
        GameProcess _gameProcess = new GameProcess();
        bool _gamePaused = false;
        
        public GameForm()
        {
            InitializeComponent();
            this.DoubleBuffered = true;     
        }

        private void Game_Paint(object sender, PaintEventArgs e)
        {
            _gameProcess.StartGame(e);
        }

        private void Game_KeyDown(object sender, KeyEventArgs e)
        {

            if (e.KeyCode == Keys.Escape) 
            {
                this.Dispose();
            }

            _gameProcess.MovePacman(e);
            
        }

        private void gameTime_Tick(object sender, EventArgs e)
        {
            _gameProcess.MoveObjects();
            Invalidate();
        }

        private void Game_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void Game_KeyPress(object sender, KeyPressEventArgs e)
        {

            if ((e.KeyChar == 'p' || e.KeyChar == 'P') && _gamePaused == true)
            {
                this.gameTime.Enabled = true;
                _gamePaused = false;
                return;
            }
            
            if (e.KeyChar == 'p' || e.KeyChar == 'P') 
            {
                this.gameTime.Enabled = false;
                _gamePaused = true;
                return;
            }
        }

       
    }
}
